import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/core/values/colors.dart';
import 'package:enterprise_v6_app/app/core/values/gaps.dart';
import 'package:enterprise_v6_app/app/data/entities/double_control/get_tb_base_measures_task_entity.dart';
import 'package:enterprise_v6_app/app/modules/application/double_prevention_page/danger_investigation_page/task_allocation_hazard_investigation/allocation_details/allocation_details_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class AllocationDetailsPage extends StatelessWidget {
  AllocationDetailsPage({super.key});

  final controller = Get.put(AllocationDetailsController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColors.bg_color_grey,
      appBar: CustomAppBar(
        titleText: '详情',
      ),
      body: GetBuilder(
          init: controller,
          builder: (_) {
            return SingleChildScrollView(
              child: Column(
                children: [
                  _titleBg(),
                  Container(
                    height: 40.w,
                    width: double.infinity,
                    color: const Color(0xFFF4F7FF),
                    alignment: Alignment.centerLeft,
                    padding: EdgeInsets.only(left: 40.w),
                    child: Text(
                      '管控手段：${controller.data?.controlMeasuresLabel??''}',
                      style: TextStyle(
                        fontSize: 16.sp,
                      ),
                    ),
                  ),
                  Container(
                    color: Colors.white,
                    padding: EdgeInsets.only(top: 20.w, bottom: 20.w),
                    child: Column(
                      children: [
                        _title('隐患排查内容：', controller.data?.troubleshootContent ?? ''),
                        _title('任务类别：', controller.data?.workKindLabel ?? ''),
                        Visibility(
                          visible: controller.isShowSeason,
                          child: Container(
                            padding: EdgeInsets.only(left: 40.w, right: 20.w),
                            color: Colors.white,
                            child: Column(
                              children: controller.allCycleChange != null
                                  ? controller.allCycleChange!.map((item) {
                                return Column(
                                  children: [
                                    _selectWidget(item, context),
                                    AppGaps.vGap16,
                                  ],
                                );
                              }).toList()
                                  : [],
                            ),
                          ),
                        ),
                        // _title('周期档次：', '${controller.data?.troubleshootContent}'),
                        Visibility(
                          visible: !controller.isShowSeason,
                          child: Column(
                            children: [
                              _title('巡检周期：', controller.data?.checkCycle ??''),
                              _title('巡检周期单位：', controller.data?.checkCycleUnitLabel ??''),
                              _title('工作时段：', '${controller.data?.workStartTime ??''}-${controller.data?.workEndTime ??''}'),
                              _title('工作日类型：', controller.data?.workDayTypeLabel ??''),
                            ],
                          ),
                        ),
                        _title('仪表：', controller.data?.instrumentId ?? ''),
                        _title('创建人：', controller.data?.createBy ?? ''),
                        _title('创建时间：', controller.data?.createDate ?? ''),
                        _title('最后修改人：', controller.data?.updateBy ?? ''),
                        _title('最后修改时间：', controller.data?.updateDate ?? ''),
                      ],
                    ),
                  ),
                ],
              ),
            );
          }),
    );
  }

  /// 标题背景分隔栏
  Widget _titleBg() {
    return Column(
      children: [
        AppGaps.vGap12,
        Container(
          height: 2.w,
          color: const Color(0xFF587DF5),
        ),
      ],
    );
  }

  /// 标题
  Widget _title(String title, String? value) {
    return Container(
      padding: EdgeInsets.only(top: 8.w, bottom: 8.w),
      child: Row(
        children: [
          AppGaps.hGap40,
          Text(
            title,
            style: TextStyle(
              color: const Color(0xFF444444),
              fontSize: 14.sp,
              fontWeight: FontWeight.w400,
            ),
          ),
          if (value != null)
            Expanded(
              child: Text(
                value,
                style: TextStyle(
                  color: const Color(0xFF7C7D93),
                  fontSize: 14.sp,
                  fontWeight: FontWeight.w400,
                ),
              ),
            ),
        ],
      ),
    );
  }

  Widget _selectWidget(GetTbBaseMeasuresTaskWorkKindCycleChangeList item, BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.start,
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisSize: MainAxisSize.min,
      children: [
        AppGaps.vGap8,
        Text(
          '季节：${item.attribute}',
          style: TextStyle(
            fontWeight: FontWeight.w400,
            fontSize: 14.sp,
            color: const Color(0xFF444444),
          ),
        ),
        _title('巡检周期单位：', item.checkCycleUnitLabel??'空'),
        _title('巡检周期：', '${item.checkCycle}'),
        _title('工作时段：', '${item.hourStartTime??'空'}至${item.hourEndTime??'空'}'),
        _title('工作日类型：', item.executeTypeLabel??'空'),
      ],
    );
  }
}
